From: Jimi Xenidis Date: Thu, 7 Sep 2006 05:30:12 +0000 (-0400) Subject: [POWERPC][XEN] More Robust Memory Checking X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15658^2~84 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=2d02b025d497b5bd659899d82c32b469abc93f73;p=xen.git [POWERPC][XEN] More Robust Memory Checking This patch allows the platform to define the "IO Hole" of addressibility and checks that even Dom0 does not try to Map "Remote" memory that is not there. Also replaces some panic calls with WARN(); and returns failure. Signed-off-by: Jimi Xenidis Signed-off-by: Hollis Blanchard --- diff --git a/xen/arch/powerpc/mm.c b/xen/arch/powerpc/mm.c index 1014c041cf..3a8e103a50 100644 --- a/xen/arch/powerpc/mm.c +++ b/xen/arch/powerpc/mm.c @@ -229,16 +229,6 @@ extern void copy_page(void *dp, void *sp) } } -static int mfn_in_hole(ulong mfn) -{ - /* totally cheating */ - if (mfn >= (0xf0000000UL >> PAGE_SHIFT) && - mfn < (((1UL << 32) - 1) >> PAGE_SHIFT)) - return 1; - - return 0; -} - static uint add_extent(struct domain *d, struct page_info *pg, uint order) { struct page_extents *pe; @@ -339,7 +329,7 @@ int allocate_rma(struct domain *d, unsigned int order) return 0; } -ulong pfn2mfn(struct domain *d, long pfn, int *type) +ulong pfn2mfn(struct domain *d, ulong pfn, int *type) { ulong rma_base_mfn = page_to_mfn(d->arch.rma_page); ulong rma_size_mfn = 1UL << d->arch.rma_order; @@ -356,7 +346,7 @@ ulong pfn2mfn(struct domain *d, long pfn, int *type) } if (test_bit(_DOMF_privileged, &d->domain_flags) && - mfn_in_hole(pfn)) { + cpu_io_mfn(pfn)) { if (type) *type = PFN_TYPE_IO; return pfn; @@ -374,7 +364,8 @@ ulong pfn2mfn(struct domain *d, long pfn, int *type) /* This hack allows dom0 to map all memory, necessary to * initialize domU state. */ - if (test_bit(_DOMF_privileged, &d->domain_flags)) { + if (test_bit(_DOMF_privileged, &d->domain_flags) && + pfn < max_page) { if (type) *type = PFN_TYPE_REMOTE; return pfn; diff --git a/xen/arch/powerpc/powerpc64/ppc970.c b/xen/arch/powerpc/powerpc64/ppc970.c index d9f01b727f..05fde31dec 100644 --- a/xen/arch/powerpc/powerpc64/ppc970.c +++ b/xen/arch/powerpc/powerpc64/ppc970.c @@ -88,6 +88,19 @@ unsigned int cpu_extent_order(void) return log_large_page_sizes[0] - PAGE_SHIFT; } + +/* This is more a platform thing than a CPU thing, but we only have + * one platform now */ +int cpu_io_mfn(ulong mfn) +{ + /* totally cheating */ + if (mfn >= (2UL << (30 - PAGE_SHIFT)) && /* 2GiB */ + mfn < (4UL << (30 - PAGE_SHIFT))) /* 4GiB */ + return 1; + + return 0; +} + static u64 cpu0_hids[6]; static u64 cpu0_hior; diff --git a/xen/arch/powerpc/usercopy.c b/xen/arch/powerpc/usercopy.c index 8ac16e6c69..0665052c39 100644 --- a/xen/arch/powerpc/usercopy.c +++ b/xen/arch/powerpc/usercopy.c @@ -56,15 +56,21 @@ static unsigned long paddr_to_maddr(unsigned long paddr) case PFN_TYPE_RMA: case PFN_TYPE_LOGICAL: break; + case PFN_TYPE_REMOTE: + /* I don't think this should ever happen, but I suppose it + * could be possible */ printk("%s: Dom:%d paddr: 0x%lx type: REMOTE\n", __func__, d->domain_id, paddr); WARN(); break; + + case PFN_TYPE_IO: default: - panic("%s: Dom:%d paddr: 0x%lx bad type:0x%x\n", + printk("%s: Dom:%d paddr: 0x%lx bad type: 0x%x\n", __func__, d->domain_id, paddr, mtype); - break; + WARN(); + return 0; } pa <<= PAGE_SHIFT; pa |= offset; diff --git a/xen/include/asm-powerpc/mm.h b/xen/include/asm-powerpc/mm.h index 7f658ad417..320f33bcf1 100644 --- a/xen/include/asm-powerpc/mm.h +++ b/xen/include/asm-powerpc/mm.h @@ -241,7 +241,7 @@ extern int update_grant_va_mapping(unsigned long va, #define PFN_TYPE_IO 3 #define PFN_TYPE_REMOTE 4 -extern ulong pfn2mfn(struct domain *d, long pfn, int *type); +extern ulong pfn2mfn(struct domain *d, ulong pfn, int *type); /* Arch-specific portion of memory_op hypercall. */ long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg); diff --git a/xen/include/asm-powerpc/processor.h b/xen/include/asm-powerpc/processor.h index 62a17545e6..0464010fee 100644 --- a/xen/include/asm-powerpc/processor.h +++ b/xen/include/asm-powerpc/processor.h @@ -46,6 +46,7 @@ extern int cpu_rma_valid(unsigned int log); extern uint cpu_large_page_orders(uint *sizes, uint max); extern void cpu_initialize(int cpuid); extern void cpu_init_vcpu(struct vcpu *); +extern int cpu_io_mfn(ulong mfn); extern void save_cpu_sprs(struct vcpu *); extern void load_cpu_sprs(struct vcpu *);